package com.example.core.service;

import com.example.core.po.BasePo;
import com.example.core.vo.BaseVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class DispatchServiceImpl implements DispatchService {

    @Resource
    private List<BaseCoreService> baseCoreServices = new ArrayList<>();

    @Resource
    private List<BaseOuterService> baseOuterServices = new ArrayList<>();

    @Override
    public void save(BasePo po) throws Exception {
        for (BaseCoreService baseCoreService : baseCoreServices) {
            baseCoreService.save(po);
        }
        for (BaseOuterService baseOuterService : baseOuterServices) {
            baseOuterService.save(po);
        }
    }

    @Override
    public void update(BasePo po) throws Exception {
        for (BaseCoreService baseCoreService : baseCoreServices) {
            baseCoreService.update(po);
        }
        for (BaseOuterService baseOuterService : baseOuterServices) {
            baseOuterService.update(po);
        }
    }

    @Override
    public void delete(BasePo po) throws Exception {
        for (BaseCoreService baseCoreService : baseCoreServices) {
            baseCoreService.delete(po);
        }
        for (BaseOuterService baseOuterService : baseOuterServices) {
            baseOuterService.delete(po);
        }
    }

    @Override
    public void toPo(BasePo po, BaseVo vo) throws Exception {
        for (BaseCoreService baseCoreService : baseCoreServices) {
            baseCoreService.toPo(po, vo);
        }
        for (BaseOuterService baseOuterService : baseOuterServices) {
            baseOuterService.toPo(po, vo);
        }
    }

    @Override
    public void toVo(BasePo po, BaseVo vo) throws Exception {
        for (BaseCoreService baseCoreService : baseCoreServices) {
            baseCoreService.toVo(po, vo);
        }
        for (BaseOuterService baseOuterService : baseOuterServices) {
            baseOuterService.toVo(po, vo);
        }
    }
}
